#ifndef MULTISCREENWIDGET_H
#define MULTISCREENWIDGET_H

#include <QWidget>
#include <QList>
#include <QRect>
#include <QImage>
#include "protocol.h"

class MultiScreenWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MultiScreenWidget(QWidget *parent = nullptr);
    ~MultiScreenWidget();
    
    // 设置协议处理器
    void setProtocol(Protocol *protocol);
    
    // 设置屏幕布局
    void setScreenLayout(const QList<QRect> &screenGeometries);
    
    // 更新桌面图像
    void updateDesktop(const QImage &image);
    
    // 进入/退出全屏模式
    void setFullScreen(bool fullScreen);
    bool isFullScreen() const;

protected:
    void paintEvent(QPaintEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;

private:
    void setupScreens();
    void updateLayout();
    QRect mapToRemoteCoordinates(const QPoint &localPos) const;
    
    Protocol *protocol;
    QList<QRect> screenGeometries;
    QList<QRect> screenAvailableGeometries;
    QImage desktopImage;
    bool fullScreenMode;
    
    // 用于坐标映射的变量
    QRect virtualGeometry;
    double scaleX;
    double scaleY;
};

#endif // MULTISCREENWIDGET_H